<template>
  <!-- 回款计划 -->
  <div class="position-btn">
    <el-dropdown>
      <el-button class="filter-btn"
        >请选择合同<el-icon class="el-icon--right"><ArrowDown /></el-icon
      ></el-button>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item v-for="item in contractList" :key="item.id">{{ item.name }}</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <el-button class="ml-12" icon="RefreshRight" @click="handleReset">重置</el-button>
    <el-button type="primary" @click="openAddPlan">新增回款计划</el-button>
  </div>

  <el-scrollbar class="return-money-plan">
    <div class="item" v-for="(item, index) in 10" :key="index">
      <div class="header flx-justify-between">
        <div class="left flx-align-center">
          <div class="label">
            <div class="number">合同编号：</div>
            <div class="value">HT202404031200</div>
            <el-icon class="pointer" color="#3370FF" v-copy="item"><DocumentCopy /></el-icon>
          </div>
          <div class="label">
            <div class="number">合同名称：</div>
            <div class="value">北凉商标注册合同</div>
            <el-icon class="pointer" color="#3370FF" v-copy="item"><DocumentCopy /></el-icon>
          </div>
        </div>
        <el-button type="primary" plain @click="openCreateDrawer(item)">新增回款</el-button>
      </div>

      <el-scrollbar class="content">
        <el-steps :active="2" align-center>
          <el-step title="合同首款" v-for="(item, index) in 3" :key="index">
            <template #description>
              <div class="text-grey">回款金额(元)：<span>500.00</span></div>
              <div class="text-grey">截止日期：<span>2024-08-05</span></div>
            </template>
          </el-step>
        </el-steps>
      </el-scrollbar>
    </div>
  </el-scrollbar>

  <!-- 新增回款计划 -->
  <add-plan v-if="showAddPlan" ref="addPlanRef" @close="showAddPlan = false" @refresh="getList"></add-plan>

  <!-- 新增回款 -->
  <add-return-money v-if="showAddReturnMoney" ref="addReturnMoneyRef" @close="showAddReturnMoney = false"></add-return-money>
</template>

<script lang="ts" setup>
import { get } from "sortablejs";
import { nextTick, ref } from "vue";
import AddPlan from "./components/AddPlan.vue";
import AddReturnMoney from "./components/Add.vue";

const contractList = ref([{ id: 1, name: "合同1" }]);

// 获取回款计划列表
const params = ref({});
const getList = () => {
  console.log("获取回款计划列表");
};
getList();
// 重置
const handleReset = () => {
  params.value = {};
  getList();
};

// 新增回款计划
const showAddPlan = ref(false);
const addPlanRef = ref();
const openAddPlan = () => {
  showAddPlan.value = true;
  nextTick(() => {
    addPlanRef.value.acceptParams({
      id: 1
    });
  });
};

// 新增回款
const showAddReturnMoney = ref(false);
const addReturnMoneyRef = ref();
const openCreateDrawer = item => {
  showAddReturnMoney.value = true;
  nextTick(() => {
    addReturnMoneyRef.value.acceptParams({
      title: "新增回款",
      id: 1
    });
  });
};
</script>

<style lang="scss" scoped>
.position-btn {
  position: absolute;
  right: 0;
  top: 0px;
}

.return-money-plan {
  .item {
    border: 1px solid #ebeef5;
    border-radius: 4px;
    margin-bottom: 12px;

    .header {
      background: #f5f7fa;
      height: 46px;
      padding: 0 10px;

      .number {
        color: #909399;
      }

      .label {
        display: flex;
        align-items: center;
        margin-right: 17px;

        .value {
          margin-right: 5px;
        }
      }
    }
  }

  .content {
    padding: 12px;
    .el-steps--horizontal {
      width: 100%;
    }
    .el-step.is-horizontal {
      min-width: 180px;
    }

    :deep(.el-step__head.is-finish) {
      .el-step__icon {
        background: var(--el-color-primary);
        color: #fff;
      }
    }
    :deep(.el-step__description.is-finish) span {
      color: var(--el-color-primary);
    }
  }
}
</style>
